import api from '@/common/request/index.js'
let imgUrl = 'https://mystore-1304299581.cos.ap-guangzhou.myqcloud.com/static/image/'
import tools from '@/common/utils/tools.js'
const state = {
    systemInfo: {},
    menuButtonInfo: {},
	scrollTop: 0,		//距离顶部距离
	imgUrl:"https://mystore-1304299581.cos.ap-guangzhou.myqcloud.com/static/image/",
    goods_data: [],
    tabs: [{
        id: 0,
        name: '精选好物'
    }, {
        id: 1,
        name: '美食'
    }, {
        id: 2,
        name: '生鲜'
    }, {
        id: 3,
        name: '生活'
    }, {
        id: 4,
        name: '健康'
    }, {
        id: 5,
        name: '母婴'
    }],
    banners:[],                                     // 轮播图
    //主页菜单
    menu: [{										//菜单
        img: imgUrl + 'menu1.png',
        label: '我的积分',
        url: '/pages/user/score/index'
    }, {
        img: imgUrl + 'menu2.png',
        label: '礼品兑换',
        url: '/pages/present/index'
    }, {
        img: imgUrl + 'menu3.png',
        label: '特惠商家',
        url: '/pages/seller/index'
    }, {
        img: imgUrl + 'menu4.png',
        label: '积分游戏',
        url: '/pages/user/score/game/index'
    }, {
        img: imgUrl + 'menu5.png',
        label: '赚积分',
        url: '/pages/user/score/task/index'
    }, {
        img: imgUrl + 'menu6.png',
        label: '业务申请',
        url: ''
    }, {
        img: imgUrl + 'menu7.png',
        label: '积分攻略',
        url: '/pages/user/score/earn/index'
    }, {
        img: imgUrl + '/menu8.png',
        label: '人气拼团',
        url: '/pages/seller/group/index'
    }],
    tabbarActive: 2,
    sellers: [],
    LimitACoupons: [] ,// 限时福利
    newfit: [],
    groupGood: [],
    is_newUser: 0,
    isLimitASum: 0,
    islimitFits: 0,
    limitFits: [],      // 特惠福利
    points: 0,          // 剩余积分
	taskList: [],       // 任务列表
	getSharePoints: 0,    // 分享积分
	boutique: [] ,// 精品
	NewDetail: [] // 公告详情
}
// 同步
const mutations = {
    set_tabbarActive(state, payload) {
        state.tabbarActive = payload
    },
    set_systemInfo(state, payload) {
        state.systemInfo = payload
    },
    set_menuButtonInfo(state, payload) {
        state.menuButtonInfo = payload
    },
	//设置距离顶部距离
	set_scrollTop(state,payload) {
		state.scrollTop = payload	
	},
    set_is_newUser(state,payload) {
        state.is_newUser = payload
    },
    set_isLimitASum(state,payload) {
        state.isLimitASum = payload
    },
    set_islimitFits(state,payload) {
        state.islimitFits = payload
    }
}
// 异步
const actions = {
  get_tabbarActive( {commit }, payload) {
      commit('set_tabbarActive', payload)
  },
  get_systemInfo( {commit}, payload) {
      commit('set_systemInfo', payload)
  },
  get_menuButtonInfo( {commit}, payload) {
      commit('set_menuButtonInfo', payload)
  },
    get_scrollTop( {commit}, payload ) {
  	  commit('set_scrollTop',payload)
    },
  // 查询商家
  get_shoppage({commit, ...a}, payload) {
  	  return new Promise((resolve, reject) => {
  		  api('shoppage', payload).then(res => {
  			  state.sellers = res.data.data
  		  })
  	  })
  },
    // 获取商品信息
    get_goods({commit, state}, payload) {
        return new Promise((resolve, reject) => {
            api('giftpage', payload).then(res => {
                state.boutique = res.data.data
            })
        })
    },
	get_base({commit, state}, payload) {
	    state.banners = payload
	},
	get_fun({commit, state}, payload) {
	    state.menu = payload
	},
	get_NewDetail({commit, state}, payload) {
	    state.NewDetail = payload
	},
	get_LimitACoupons({commit, state}, payload) {
		return new Promise((resolve, reject) => {
		    api('baselistBankCoupon', payload).then(res => {
				res.data.forEach(item => {
					item.use_end_time = tools.time_data(item.use_end_time, 'f_date')
					item.use_start_time = tools.time_data(item.use_start_time, 'f_date')
					item.type = 0;
				})
		        state.LimitACoupons = res.data
		    })
		})
	},
	get_newfit({commit, state}, payload) {
		return new Promise((resolve, reject) => {
		    api('baselistBankCoupon', payload).then(res => {
				res.data.forEach(item => {
					item.use_end_time = tools.time_data(item.use_end_time, 'f_date')
					item.use_start_time = tools.time_data(item.use_start_time, 'f_date')
					item.type = 0;
				})
		        state.newfit = res.data
		    })
		})
	},
    get_limitFits({commit, state}, payload) {
		return new Promise((resolve, reject) => {
		    api('giftpage', payload).then(res => {
		        state.limitFits = res.data.data
		    })
		})
    },
	get_groupGood({commit, state}, payload) {
	    state.groupGood = payload
	},
    get_is_newUser({commit}, payload) {
        commit('set_is_newUser', payload);
    },
    get_isLimitASum({commit}, payload) {
        commit('set_isLimitASum', payload);
    },
    get_islimitFits({commit}, payload) {
        commit('set_islimitFits', payload);
    },
    get_Points({commit, state}, payload) {
        return new Promise((resolve, reject) => {
            api('getPoints').then(res => {
                state.points = res.data
            })
        })
    },
    get_getSharePoints({commit, state}, payload) {
        return new Promise((resolve, reject) => {
            api('getSharePoints').then(res => {
                state.getSharePoints = res.data
            })
        })
    },
}


export default {
    namespaced: true,
    state,
    mutations,
    actions
}